package com.nsy.service.impl;

import com.github.pagehelper.PageHelper;
import com.nsy.dao.ProductMapper;
import com.nsy.dao.UserMapper;
import com.nsy.pojo.Product;
import com.nsy.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductServiceimpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    //获取所有商品
    @Override
    public List<Product> getAllProducts(String productName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> allProducts = productMapper.getAllProducts(productName);
        return allProducts;
    }

    @Override
    public Product getProductById(Integer id) {
        Product productById = productMapper.getProductById(id);
        return productById;
    }

    @Override
    public int addProduct(Product product) {
        int i = productMapper.addProduct(product);
        return i;
    }

    @Override
    public int deleteProduct(Integer id) {
        int i = productMapper.deleteProduct(id);
        return i;
    }

    @Override
    public int editProduct(Product product) {
        int i = productMapper.editProduct(product);
        return i;
    }

    @Override
    public int deleteAllProduct(List<String> ids) {
        int i = productMapper.deleteAllProduct(ids);
        return i;
    }

    @Override
    public Product getProductByProductName(String productName) {
        Product productByProductName = productMapper.getProductByProductName(productName);
        return productByProductName;
    }

    @Override
    public Product detailProduct(Integer id) {
        Product detailProduct = productMapper.detailProduct(id);
        return detailProduct;
    }
}
